/******************************************************************************

           Copyright @2024 - 2044 Shenzhen dcenzix Technology Ltd.

 ******************************************************************************
@file cola_os.h
@brief
@author xiexiongwu
@version V1.0
@date 2024骞�5鏈�25鏃�

******************************************************************************/
#ifndef __COLA_OS_H__
#define __COLA_OS_H__

/*----------------------------------------------*
 * 鍖呭惈澶存枃浠�                                   *
 *----------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>

/*----------------------------------------------*
 * 鏋氫妇瀹氫箟                            *
 *----------------------------------------------*/

/** \enum EN_COLA_EVENT_TYPE
 *  \brief 浜嬩欢绫诲瀷
 */
typedef enum COLA_EVENT_TYPE
{
    EN_COLA_EVENT_ALARM = 1 << 0,
    EN_COLA_EVENT_DATA  = 1 << 1,
    EN_COLA_EVENT_UART  = 1 << 3,
    EN_COLA_EVENT_USR1  = 1 << 8,
    EN_COLA_EVENT_USR2  = 1 << 9,
    EN_COLA_EVENT_MSG  = 1 << 15,
} EN_COLA_EVENT_TYPE;

/** \enum COLA_TIMER_TYPE
 *	\brief 瀹氭椂绫诲瀷
 */
typedef enum COLA_TIMER_TYPE
{
    EN_COLA_TIMER_ALWAYS     = 0x00, ///< 鍛ㄦ湡浠诲姟
    EN_COLA_TIMER_ONE_SHOT   = 0x01, ///< 鍗曟浠诲姟

} EN_COLA_TIMER_TYPE;

/** \enum EN_COLA_TASK_TYPE
 *	\brief 浠诲姟绫诲瀷
 */
typedef enum COLA_TASK_TYPE
{
    EN_COLA_TASK_TASK	= 0x00, 	///< 浜嬩欢浠诲姟
    EN_COLA_TASK_TIMER	= 0x01, 	///< 瀹氭椂浠诲姟

} EN_COLA_TASK_TYPE;
/*----------------------------------------------*
 * 瀹忓畾涔�                                          *
 *----------------------------------------------*/
typedef void (*cbFunc)(void *arg, uint32_t event);

/*----------------------------------------------*
 * 缁撴瀯浣撳畾涔�                              *
 *----------------------------------------------*/
typedef struct task_s
{
    uint32_t     		taskNum;     ///< 浠诲姟缂栧彿
    uint32_t    		period;      ///< 瀹氭椂鍛ㄦ湡
    EN_COLA_TIMER_TYPE  timerType;   ///< 瀹氭椂鍣ㄧ被鍨�
    uint32_t    		timerTick;   ///< 瀹氭椂璁℃暟
    bool        		start;       ///< 寮�濮嬪惎鍔�
    bool        		run;         ///< 浠诲姟杩愯鏍囧織
    EN_COLA_TASK_TYPE   taskType;    ///< 浠诲姟鏍囧織鏄富浠诲姟杩樻槸瀹氭椂浠诲姟
    uint32_t			event;       ///< 椹卞姩浜嬩欢
    cbFunc      		func;        ///< 鍥炶皟鍑芥暟
    void       			*usr;        ///< 鐢ㄦ埛鎺ュ彛
    struct task_s 		*next;
} __attribute__((aligned(4))) task_t;

/*----------------------------------------------*
 * 鍏ㄥ眬鍙橀噺                                     *
 *----------------------------------------------*/
extern volatile unsigned int jiffies;

/*----------------------------------------------*
 * 鍑芥暟鍘熷瀷璇存槑                                     *
 *----------------------------------------------*/

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

extern bool cola_clear_event(task_t *task, uint32_t event);
extern void cola_delay_ms(uint32_t ms);
extern bool cola_set_event(task_t *task, uint32_t event);
extern bool cola_task_create(task_t *task, cbFunc func, void *arg);
extern bool cola_task_delete(task_t *task);
extern bool cola_task_is_exists(task_t *task);
extern void cola_task_loop(void);
extern bool cola_timer_create(task_t *timer, cbFunc func, void *arg);
extern bool cola_timer_delete(task_t *timer);
extern bool cola_timer_start(task_t *timer, EN_COLA_TIMER_TYPE time_type, uint32_t time_ms);
extern bool cola_timer_stop(task_t *timer);
extern void cola_timer_ticker(void);
extern unsigned int cola_get_ticker(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */


#endif /* __COLA_OS_H__ */
